﻿namespace HRM.CORE
{
    using DevExpress.Utils;
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Controls;
    using HRM.CORE;
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms; using Common;

    public class xfmShiftOption : XtraForm
    {
        private SimpleButton btCancel;
        private SimpleButton btCreate;
        private CheckEdit checkEdit1;
        private IContainer components;
        private DevExpress.Utils.ImageCollection imageCollection1;
        private HRM_TIMEKEEPER_TABLELIST l_TimeKeeperTableList;
        private ImageListBoxControl lbTimeKeeperShiftList;
        private LabelControl lcDescription;
        private bool m_IsClosing;
        private int m_Month;
        private int m_Year;
        private PanelControl panelControl1;
        private RadioGroup radioGroup1;

        public event ClosedHandler Closed;

        public event CreateNewDataChangedHander CreateNewDataChanged;

        public event CreateOldDataChangedHandler CreateOldDataChanged;

        public xfmShiftOption()
        {
            this.components = null;
            this.m_Month = 0;
            this.m_Year = 0;
            this.l_TimeKeeperTableList = new HRM_TIMEKEEPER_TABLELIST();
            this.m_IsClosing = true;
            this.InitializeComponent();
            this.LoadTimeKeeperShiftList();
        }

        public xfmShiftOption(int Month, int Year)
        {
            this.components = null;
            this.m_Month = 0;
            this.m_Year = 0;
            this.l_TimeKeeperTableList = new HRM_TIMEKEEPER_TABLELIST();
            this.m_IsClosing = true;
            this.InitializeComponent();
            this.LoadTimeKeeperShiftList();
            this.m_Month = Month;
            this.m_Year = Year;
            this.Text = "T\x00f9y chọn tạo bảng xếp ca, bảng chấm c\x00f4ng cho th\x00e1ng " + this.m_Month.ToString() + "/" + this.m_Year.ToString();
        }

        private void btCancel_Click(object sender, EventArgs e)
        {
            this.m_IsClosing = true;
            this.CancelThis();
        }

        private void btCreate_Click(object sender, EventArgs e)
        {
            if (this.radioGroup1.SelectedIndex == 0)
            {
                this.RaiseCreateNewDataChangedHander();
            }
            else
            {
                string str = (this.lbTimeKeeperShiftList.SelectedItem as ImageListBoxItem).Value.ToString();
                char[] separator = new char[] { ' ', '-' };
                string[] strArray = str.Split(separator);
                int month = Convert.ToInt32(strArray[1].ToString());
                int year = Convert.ToInt32(strArray[2].ToString());
                this.RaiseCreateOldDataChangedHander(month, year);
            }
            this.m_IsClosing = false;
            base.Close();
        }

        private void CancelThis()
        {
            if (this.m_IsClosing)
            {
                this.RaiseClosedHandler();
            }
            base.Close();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            ComponentResourceManager manager = new ComponentResourceManager(typeof(xfmShiftOption));
            this.radioGroup1 = new RadioGroup();
            this.btCreate = new SimpleButton();
            this.imageCollection1 = new DevExpress.Utils.ImageCollection(this.components);
            this.btCancel = new SimpleButton();
            this.lcDescription = new LabelControl();
            this.panelControl1 = new PanelControl();
            this.checkEdit1 = new CheckEdit();
            this.lbTimeKeeperShiftList = new ImageListBoxControl();
            this.radioGroup1.Properties.BeginInit();
            this.imageCollection1.BeginInit();
            this.panelControl1.BeginInit();
            this.panelControl1.SuspendLayout();
            this.checkEdit1.Properties.BeginInit();
            ((ISupportInitialize) this.lbTimeKeeperShiftList).BeginInit();
            base.SuspendLayout();
            this.radioGroup1.Location = new Point(13, 60);
            this.radioGroup1.Name = "radioGroup1";
            this.radioGroup1.Properties.Appearance.BackColor = Color.Transparent;
            this.radioGroup1.Properties.Appearance.Options.UseBackColor = true;
            this.radioGroup1.Properties.BorderStyle = BorderStyles.NoBorder;
            this.radioGroup1.Properties.Items.AddRange(new RadioGroupItem[] { new RadioGroupItem(null, "Tạo mới bảng xếp ca, bảng chấm c\x00f4ng"), new RadioGroupItem(null, "Dựa theo c\x00e1c bảng xếp ca, bảng chấm c\x00f4ng ở ph\x00eda dưới") });
            this.radioGroup1.Size = new Size(0x1be, 0x3a);
            this.radioGroup1.TabIndex = 0;
            this.radioGroup1.SelectedIndexChanged += new EventHandler(this.radioGroup1_SelectedIndexChanged);
            this.btCreate.ImageIndex = 2;
            this.btCreate.ImageList = this.imageCollection1;
            this.btCreate.Location = new Point(250, 10);
            this.btCreate.Name = "btCreate";
            this.btCreate.Size = new Size(0x62, 0x17);
            this.btCreate.TabIndex = 2;
            this.btCreate.Text = "Tạo (>>)";
            this.btCreate.Click += new EventHandler(this.btCreate_Click);
            this.imageCollection1.ImageStream = (ImageCollectionStreamer) manager.GetObject("imageCollection1.ImageStream");
            this.imageCollection1.Images.SetKeyName(0, "ico_alpha_Search_16x16.png");
            this.imageCollection1.Images.SetKeyName(1, "ico_alpha_Delete_16x16.png");
            this.imageCollection1.Images.SetKeyName(2, "document2.png");
            this.imageCollection1.Images.SetKeyName(3, "open-16x16.png");
            this.btCancel.ImageIndex = 1;
            this.btCancel.ImageList = this.imageCollection1;
            this.btCancel.Location = new Point(0x169, 10);
            this.btCancel.Name = "btCancel";
            this.btCancel.Size = new Size(0x62, 0x17);
            this.btCancel.TabIndex = 3;
            this.btCancel.Text = "Hủy (X)";
            this.btCancel.Click += new EventHandler(this.btCancel_Click);
            this.lcDescription.Appearance.Options.UseTextOptions = true;
            this.lcDescription.Appearance.TextOptions.WordWrap = WordWrap.Wrap;
            this.lcDescription.AutoSizeMode = LabelAutoSizeMode.None;
            this.lcDescription.Location = new Point(0x11, 7);
            this.lcDescription.Name = "lcDescription";
            this.lcDescription.Size = new Size(0x1be, 0x31);
            this.lcDescription.TabIndex = 4;
            this.lcDescription.Text = manager.GetString("lcDescription.Text");
            this.panelControl1.Appearance.BackColor = Color.Transparent;
            this.panelControl1.Appearance.Options.UseBackColor = true;
            this.panelControl1.BorderStyle = BorderStyles.NoBorder;
            this.panelControl1.Controls.Add(this.checkEdit1);
            this.panelControl1.Controls.Add(this.btCancel);
            this.panelControl1.Controls.Add(this.btCreate);
            this.panelControl1.Dock = DockStyle.Bottom;
            this.panelControl1.Location = new Point(0, 0x124);
            this.panelControl1.Name = "panelControl1";
            this.panelControl1.Size = new Size(0x1db, 0x2b);
            this.panelControl1.TabIndex = 6;
            this.checkEdit1.EditValue = true;
            this.checkEdit1.Location = new Point(15, 13);
            this.checkEdit1.Name = "checkEdit1";
            this.checkEdit1.Properties.Caption = "Ph\x00e1t sinh theo ng\x00e0y trong th\x00e1ng";
            this.checkEdit1.Properties.ReadOnly = true;
            this.checkEdit1.Size = new Size(0xc1, 0x13);
            this.checkEdit1.TabIndex = 4;
            this.lbTimeKeeperShiftList.Enabled = false;
            this.lbTimeKeeperShiftList.HighlightedItemStyle = HighlightStyle.Skinned;
            this.lbTimeKeeperShiftList.Location = new Point(0x11, 0x7c);
            this.lbTimeKeeperShiftList.Name = "lbTimeKeeperShiftList";
            this.lbTimeKeeperShiftList.Size = new Size(0x1ba, 0x9e);
            this.lbTimeKeeperShiftList.TabIndex = 7;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x1db, 0x14f);
            base.Controls.Add(this.lbTimeKeeperShiftList);
            base.Controls.Add(this.panelControl1);
            base.Controls.Add(this.lcDescription);
            base.Controls.Add(this.radioGroup1);
            base.FormBorderStyle = FormBorderStyle.FixedSingle;
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "xfmShiftOption";
            base.ShowIcon = false;
            base.ShowInTaskbar = false;
            base.StartPosition = FormStartPosition.CenterScreen;
            this.Text = "T\x00f9y chọn tạo bảng xếp ca, bảng chấm c\x00f4ng cho th\x00e1ng mới";
            base.FormClosing += new FormClosingEventHandler(this.xfmShiftOption_FormClosing);
            this.radioGroup1.Properties.EndInit();
            this.imageCollection1.EndInit();
            this.panelControl1.EndInit();
            this.panelControl1.ResumeLayout(false);
            this.checkEdit1.Properties.EndInit();
            ((ISupportInitialize) this.lbTimeKeeperShiftList).EndInit();
            base.ResumeLayout(false);
        }

        private void LoadTimeKeeperShiftList()
        {
            DataTable list = this.l_TimeKeeperTableList.GetList();
            if (list.Rows.Count == 0)
            {
                this.radioGroup1.Enabled = false;
            }
            foreach (DataRow row in list.Rows)
            {
                this.lbTimeKeeperShiftList.Items.Add(row["TimeKeeperTableListName"].ToString());
            }
        }

        private void radioGroup1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.radioGroup1.SelectedIndex == 0)
            {
                this.lbTimeKeeperShiftList.Enabled = false;
            }
            else
            {
                this.lbTimeKeeperShiftList.Enabled = true;
            }
        }

        private void RaiseClosedHandler()
        {
            if (this.Closed != null)
            {
                this.Closed(this);
            }
        }

        private void RaiseCreateNewDataChangedHander()
        {
            if (this.CreateNewDataChanged != null)
            {
                this.CreateNewDataChanged(this);
            }
        }

        private void RaiseCreateOldDataChangedHander(int Month, int Year)
        {
            if (this.CreateOldDataChanged != null)
            {
                this.CreateOldDataChanged(this, Month, Year);
            }
        }

        private void xfmShiftOption_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!this.m_IsClosing)
            {
                this.m_IsClosing = false;
            }
            else
            {
                this.m_IsClosing = true;
            }
            this.CancelThis();
        }

        public delegate void ClosedHandler(object sender);

        public delegate void CreateNewDataChangedHander(object sender);

        public delegate void CreateOldDataChangedHandler(object sender, int Month, int Year);
    }
}

